<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePostsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create("posts", function(Blueprint $table){
			$table->increments("id");
			$table->string("title","255");
			$table->text("content");
			$table->string("img","255");
			$table->integer("viewed")->unsigned()->default(0);
			$table->integer("votes")->unsigned()->default(0);
			$table->integer("categorieID")->unsigned()->default(0);
			$table->integer("userID")->unsigned()->default(0);
			//tao quan he
			$table->foreign("userID")->references("id")->on("users")->onDelete("cascade");
			$table->foreign("categorieID")->references("id")->on("categories")->onDelete("cascade");
			$table->timestamps();
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop("posts");
	}

}
